package com.sy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sy.PageVO;
import com.sy.dto.AdminsEditDTO;
import com.sy.dto.PageDTO;
import com.sy.mapper.AdminsMapper;
import com.sy.pojo.Admins;
import com.sy.service.AdminsService;
import com.sy.vo.AdminsPageVO;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @className: AdminsServiceImpl
 * @author: Mr.Liu
 * @date: 2025/10/29 13:57
 * @Version: 1.0
 * @description:管理员业务实现
 */
@Service
public class AdminsServiceImpl extends ServiceImpl<AdminsMapper, Admins> implements AdminsService {
    @Resource
    private AdminsMapper adminsMapper;

    @Override
    public PageVO<AdminsPageVO> adminsPage(PageDTO pageDTO) {
        //定制分页规则
        PageHelper.startPage(pageDTO.getCurPage(),pageDTO.getPageSize());
        //分页查询
        List<AdminsPageVO> adminsPageVOS = adminsMapper.adminsPage(pageDTO.getKeyword(), pageDTO.getStatus());
        //构建pageInfo
        PageInfo<AdminsPageVO> pageInfo = new PageInfo<>(adminsPageVOS);
        //构建PageVO
        return new PageVO<>(pageInfo.getPageNum(),
                pageInfo.getPageSize(),
                pageInfo.getTotal(),
                pageInfo.getList());
    }

    @Override
    public boolean updateByPrimaryKeySelective(AdminsEditDTO adminsEditDTO) {
        //构建admins
        Admins admins = new Admins();
        //属性赋值
        BeanUtils.copyProperties(adminsEditDTO,admins);
        int i =adminsMapper.updateByPrimaryKeySelective(admins);
        return i>0;
    }
}
